var app = {
  openId: GetRequest().openId,
  friend: GetRequest().state,
  hostSever: getServerHost(),
  friendHelp: '/api/longtaitou/friend',
  checkUser: '/api/longtaitou/checkUser',
  joinRes: [{
      type: 1,
      text: '  恭喜您！您已成功为好友助力一次，棒棒哒！'
    },
    {
      type: 2,
      text: '助力失败'
    },
    {
      type: 3,
      text: '已经助理过了'
    }
  ],
  init: function () {
    this.judgeFollow();
    this.gotoPlay();
  },
  judgeFollow: function () {
    // TODO: 判断是否关注
    $.get(app.hostSever + app.checkUser, {
      openId: app.openId
    }).done(
      function (rp) {
        console.log(rp);
        if ('200' == rp.code) {
          console.log(app.friend);
          app.helpFriend();
        } else if ('300' == rp.code) {
          autoshowBar('.follow');
        } else {
          alert('请刷新重试');
        }
      }
    ).fail(function () {
      alert('接口请求失败，请稍后重试');
    })

  },
  //朋友助力
  helpFriend: function () {
    $.get(app.hostSever + app.friendHelp, {
      openId: app.friend,
      friend: app.openId
    }).done(
      function (rp) {
        if ('200' == rp.code) {
          $('nav').text('恭喜您！您已成功为好友助力一次，棒棒哒！');
        } else if ('999' == rp.code) {
          $('nav').text(rp.msg);
        } else if ('300' == rp.code) {
          $('nav').text('关注“沃钱包”公众号，才能为您的好友成功助力~');
          autoshowBar('.follow');
        }
        setTimeout(function () {
          $('.loading').hide();
        }, 1000)
      }
    ).fail(function () {
      alert('接口请求失败，请稍后重试');
    })
  },
  gotoPlay: function () {
    $('#gotoPlayBtn').on('click', function () {
      location.href = 'http://wx1.unisk.cn/weixinLinksucaiController.do?link&id=ff808081630221220163f359691e532a&jwid=gh_fc380688dfba';
    })
  }
}
$(app.init())